package com.yxcz.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(name = "dept", catalog = "yxczoa")
public class Dept implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;
	private boolean status;
	private int sequence;
	private String shortName;
	private Dept pDept;
	private Set<Dept> childDept =new HashSet<>();  

	public Dept() {
	}

	public Dept(String name, boolean status, int sequence) {
		this.name = name;
		this.status = status;
		this.sequence = sequence;
	}


	@Id    
	@GeneratedValue(strategy = IDENTITY)

	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name", nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "status", nullable = false)
	public boolean isStatus() {
		return this.status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	@Column(name = "sequence", nullable = false)
	public int getSequence() {
		return this.sequence;
	}

	public void setSequence(int sequence) {
		this.sequence = sequence;
	}

	@Column(name = "short_name")
	public String getShortName() {
		return this.shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}


	 @ManyToOne
	 @JoinColumn(name="pid")   //外键
	 @JsonIgnore
	public Dept getpDept() {
		return pDept;
	}

	public void setpDept(Dept pDept) {
		this.pDept = pDept;
	}

	@OneToMany(mappedBy="pDept",cascade={CascadeType.REMOVE}) 
	@OrderBy("sequence asc")  
	@JsonIgnore
	public Set<Dept> getChildDept() {
		return childDept;
	}

	public void setChildDept(Set<Dept> childDept) {
		this.childDept = childDept;
	}

}
